import java.util.Scanner;

public class Test26 {



    public static void main02(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int[] a=new int[n];

            for(int i=0;i<n;i++){
                a[i]=in.nextInt();
            }
            int[] dp=new int[n];
            dp[0]=a[0];
            long sum=sumMax(a,dp);
            System.out.println(sum);
        }
    }

    public static long sumMax(int[] a,int[] dp){
        long sum=0;
        int n=a.length;
        dp[1]=Math.max(a[1],dp[0]);
        for(int i=2;i<n;i++) {
            dp[i] = Math.max(dp[i - 2] + a[i], dp[i - 1]);
        }
        for(int i: dp){
            sum=Math.max(sum,i);
        }
        return sum;
    }







    public static void main01(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) {
            String s = in.next();
            char[] ch=s.toCharArray();
            int n=s.length();
            int[] dp = new int[n];
            dp[0]=1;
            int sum=Palindromic(ch,dp);
            if(sum == 100){
                System.out.println("-1");
            }else{
                System.out.println(sum);
            }
        }
    }

    public static int Palindromic(char[] ch,int[] dp){
        int n=ch.length;
        for(int i=1;i<n;i++){
            if(ch[i] == ch[i-1] &&( dp[i-1] == 1 ||(i>=2 && dp[i-1] == dp[i-2]+1))){
                 dp[i]=dp[i-1]+1;
            }else if(ch[i] == ch[i-dp[i-1]]){
                dp[i]=dp[i-1]+2;
            }else{
                dp[i]=dp[i-1];
            }
        }
        int sum=100;
        for(int i:dp){
            if(i != 1) {
                sum = Math.min(sum, i);
            }
        }
        return sum;
    }
}
